package com.cms.jy.draft.util;

import cn.hutool.core.bean.BeanUtil;
import com.cms.jy.draft.constant.Config;
import com.cms.jy.draft.entity.*;
import com.cms.jy.draft.constant.TextAnimations;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.io.File;
import java.util.UUID;
import java.util.function.IntConsumer;

/**
 * 元素添加工具类
 * 提供添加文字、视频、音频、特效、转场等元素的快捷方式
 */
public class ElementAdder {
    
    /**
     * 添加文字到草稿
     * @param draftContent 草稿内容
     * @param text 文字元素
     */
    public static void addTextToDraft(DraftContent draftContent, Text text) {
        if (draftContent.getMaterials() == null) {
            draftContent.setMaterials(new Materials());
        }
        
        if (draftContent.getMaterials().getTexts() == null) {
            draftContent.getMaterials().setTexts(new ArrayList<>());
        }
        
        draftContent.getMaterials().getTexts().add(text);
    }
    
    /**
     * 创建带有正确格式内容的文字元素
     * @param textContent 文字内容
     * @param fontSize 字体大小
     * @return Text对象
     */
    public static Text createTextWithContent(String textContent, Effect fontName, double fontSize, boolean showShade, boolean showBold) {
        if (fontSize == 0) {
            fontSize = 15;
        }
        if (fontName == null) {
            fontName = new Effect();
        }
        Text text = new Text();
        text.setId(java.util.UUID.randomUUID().toString());
        text.setText_size((int)fontSize);
        text.setType("text");
        text.setMulti_language_current("none");
        
        // 设置与模板中"默认文字"相同的默认属性值
        text.setAdd_type(0);
        text.setAlignment(1);
        text.setBackground_alpha(0.0);
        text.setBackground_color("");
        text.setBackground_height(0.14);
        text.setBackground_horizontal_offset(0.0);
        text.setBackground_round_radius(0.0);
        text.setBackground_style(0);
        text.setBackground_vertical_offset(0.0);
        text.setBackground_width(0.14);
        text.setBase_content("");
        text.setBold_width(0.0);
        text.setBorder_alpha(1.0);
        text.setBorder_color("");
        text.setBorder_width(0.08);
        
        // 创建CaptionTemplateInfo对象
        CaptionTemplateInfo captionTemplateInfo = new CaptionTemplateInfo();
        captionTemplateInfo.setCategory_id("");
        captionTemplateInfo.setCategory_name("");
        captionTemplateInfo.setEffect_id("");
        captionTemplateInfo.setIs_new(false);
        captionTemplateInfo.setPath("");
        captionTemplateInfo.setRequest_id("");
        captionTemplateInfo.setResource_id("");
        captionTemplateInfo.setResource_name("");
        captionTemplateInfo.setSource_platform(0);
        text.setCaption_template_info(captionTemplateInfo);
        
        text.setCheck_flag(7);
        
        // 创建ComboInfo对象
        ComboInfo comboInfo = new ComboInfo();
        comboInfo.setText_templates(new java.util.ArrayList<>());
        text.setCombo_info(comboInfo);
        
        // 构造符合模板格式的content JSON字符串
        String shadowStr = showShade ? "\"shadows\":[{\"diffuse\":0.02500000037252903,\"alpha\":0.0385964922606945,\"distance\":7.9999995231628418,\"content\":{\"solid\":{\"color\":[0,0,0]}},\"angle\":-45}]," : "";
        String contentJson = String.format(
            "{\"text\":\"%s\",\"styles\":[{\"fill\":{\"content\":{\"solid\":{\"color\":[1,1,1]}}},\"font\":{\"path\":\"C:/%s.ttf\",\"id\":\"%s\"},\"size\":%.1f,%s\"bold\":%s,\"range\":[0,%d]}]}",
            textContent, fontName.getName(), null == fontName.getResource_id() ? "" : fontName.getResource_id(), fontSize, shadowStr, showBold, textContent.length());
        text.setContent(contentJson);
        
        text.setFixed_height(-1.0);
        text.setFixed_width(-1.0);
        text.setFont_category_id("");
        text.setFont_category_name("");
        text.setFont_id("");
        text.setFont_name("");
        text.setFont_path("");//"D:/software/desk/Program Files (x86)/jianying/JianyingPro/5.9.0.11632/Resources/Font/SystemFont/zh-hans.ttf"
        text.setFont_resource_id(null == fontName.getResource_id() ? "" : fontName.getResource_id());
        text.setFont_size(fontSize);
        text.setFont_source_platform(0);
        text.setFont_team_id("");
        text.setFont_title("none");
        text.setFont_url("");
        List<Font> fonts = new ArrayList<>();
        if (null != fontName) {
            Font font = new Font();
            font.setCategory_name("favoured");
            font.setCategory_name("我的收藏");
            font.setEffect_id(null == fontName.getEffect_id() ? "" : fontName.getEffect_id());
            font.setFile_uri("");
            font.setPath("");
            font.setRequest_id("");
            font.setResource_id(null == fontName.getResource_id() ? "" : fontName.getResource_id());
            font.setSource_platform(0);
            font.setTitle(fontName.getName());
            fonts.add(font);
        }
        text.setFonts(fonts);
        text.setForce_apply_line_max_width(false);
        text.setGlobal_alpha(1.0);
        text.setGroup_id("");
        text.setHas_shadow(showShade);
        text.setId(UUID.randomUUID().toString());
        text.setInitial_scale(1.0);
        text.setInner_padding(-1.0);
        text.setIs_rich_text(false);
        text.setItalic_degree(0);
        text.setKtv_color("");
        text.setLanguage("");
        text.setLayer_weight(1);
        text.setLetter_spacing(0.0);
        text.setLine_feed(1);
        text.setLine_max_width(0.82);
        text.setLine_spacing(0.02);
        text.setMulti_language_current("none");
        text.setName("");
        text.setOriginal_size(new java.util.ArrayList<>());
        text.setPreset_category("");
        text.setPreset_category_id("");
        text.setPreset_has_set_alignment(false);
        text.setPreset_id("");
        text.setPreset_index(0);
        text.setPreset_name("");
        text.setRecognize_task_id("");
        text.setRecognize_type(0);
        text.setRelevance_segment(new java.util.ArrayList<>());
        text.setShadow_alpha(0.9);
        text.setShadow_angle(45.0);
        text.setShadow_distance(5.0);
        text.setShadow_color("");
        
        // 创建ShadowPoint对象
        ShadowPoint shadowPoint = new ShadowPoint();
        shadowPoint.setX(0.6363961030678928);
        shadowPoint.setY(-0.6363961030678928);
        text.setShadow_point(shadowPoint);
        
        text.setShadow_smoothing(0.45);
        text.setShape_clip_x(false);
        text.setShape_clip_y(false);
        text.setSource_from("");
        text.setStyle_name("");
        text.setSub_type(0);
        text.setSubtitle_keywords(null);
        text.setSubtitle_template_original_fontsize(0.0);
        text.setText_alpha(1.0);
        text.setText_color("#FFFFFF");
        text.setText_curve(null);
        text.setText_preset_resource_id("");
        text.setText_size((int)fontSize);
        text.setText_to_audio_ids(new java.util.ArrayList<>());
        text.setTts_auto_update(false);
        text.setTypesetting(0);
        text.setUnderline(false);
        text.setUnderline_offset(0.22);
        text.setUnderline_width(0.22);
        text.setUse_effect_default_color(true);
        
        // 创建Words对象
        Words words = new Words();
        words.setEnd_time(new java.util.ArrayList<>());
        words.setStart_time(new java.util.ArrayList<>());
        words.setText(new java.util.ArrayList<>());
        text.setWords(words);
        
        return text;
    }
    
    /**
     * 创建视频元素
     * @param path 视频路径
     * @param duration 视频时长（微秒）
     * @param width 视频宽度
     * @param height 视频高度
     * @return Video对象
     */
    public static Video createVideo(String path, long duration, int width, int height) {
        Video video = new Video();
        video.setId(java.util.UUID.randomUUID().toString());
        video.setPath(path);
        video.setDuration(duration);
        video.setWidth(width);
        video.setHeight(height);
        video.setType("video");
        video.setSource(0);
        video.setSource_platform(0);
        video.setCheck_flag(63487);
        video.setCategory_name("local");
        
        return video;
    }
    
    /**
     * 创建音频元素
     * @param path 音频路径
     * @param duration 音频时长（微秒）
     * @return Audio对象
     */
    public static Audio createAudio(String path, long duration) {
        Audio audio = new Audio();
        audio.setId(java.util.UUID.randomUUID().toString());
        audio.setPath(path);
        audio.setDuration(duration);
        audio.setType("extract_music");
        audio.setCategory_name("local");
        audio.setCheck_flag(1);
        audio.setSource_platform(0);
        
        return audio;
    }
    
    /**
     * 创建特效元素
     * @param name 特效名称
     * @param type 特效类型
     * @param value 特效值
     * @return Effect对象
     */
    public static Effect createEffect(String name, String type, double value) {
        Effect effect = new Effect();
        effect.setId(java.util.UUID.randomUUID().toString());
        effect.setName(name);
        effect.setType(type);
        effect.setValue(value);
        
        return effect;
    }
    
    /**
     * 创建转场元素
     * @param name 转场名称
     * @param duration 转场时长（微秒）
     * @param isOverlap 是否重叠
     * @return Transition对象
     */
    public static Transition createTransition(String name, long duration, boolean isOverlap) {
        Transition transition = new Transition();
        transition.setId(java.util.UUID.randomUUID().toString());
        transition.setName(name);
        transition.setDuration(duration);
        transition.setIs_overlap(isOverlap);
        transition.setCategory_name("运镜");
        
        return transition;
    }
    
    /**
     * 创建"水墨"转场元素（与模板配置完全一致）
     * @return Transition对象
     */
    public static Transition createInkTransition() {
        Transition transition = new Transition();
        transition.setId("3B846A0C-3631-49a0-B99F-E753F788711E"); // 使用模板中的ID
        transition.setName("水墨");
        transition.setDuration(466666);
        transition.setIs_overlap(true);
        transition.setCategory_id("39663");
        transition.setCategory_name("热门");
        transition.setEffect_id("2912466");
        transition.setPath("C:/Users/Administrator/AppData/Local/JianyingPro/User Data/Cache/effect/2912466/d1dd3dd8905f0b96be756bd34be1a84d");
        transition.setPlatform("all");
        transition.setRequest_id("2025090814342248E87D63EDDE174C1857");
        transition.setResource_id("6789847231873683976");
        transition.setType("transition");
        
        return transition;
    }
    
    /**
     * 创建动画元素
     * @param name 动画名称
     * @param type 动画类型（in/out）
     * @param category 动画分类
     * @param duration 动画时长（微秒）
     * @param materialType 材料类型
     * @return Animation对象
     */
    public static Animation createAnimation(String name, String type, String category, long duration, String materialType) {
        Animation animation = new Animation();
        animation.setId(java.util.UUID.randomUUID().toString());
        animation.setName(name);
        animation.setType(type);
        animation.setCategory_name(category);
        animation.setDuration(duration);
        animation.setMaterial_type(materialType);
        
        return animation;
    }
    
    /**
     * 添加视频到草稿
     * @param draftContent 草稿内容
     * @param video 视频元素
     */
    public static void addVideoToDraft(DraftContent draftContent, Video video) {
        if (draftContent.getMaterials() == null) {
            draftContent.setMaterials(new Materials());
        }
        
        if (draftContent.getMaterials().getVideos() == null) {
            draftContent.getMaterials().setVideos(new ArrayList<>());
        }
        
        draftContent.getMaterials().getVideos().add(video);
    }
    
    /**
     * 添加音频到草稿
     * @param draftContent 草稿内容
     * @param audio 音频元素
     */
    public static void addAudioToDraft(DraftContent draftContent, Audio audio) {
        if (draftContent.getMaterials() == null) {
            draftContent.setMaterials(new Materials());
        }
        
        if (draftContent.getMaterials().getAudios() == null) {
            draftContent.getMaterials().setAudios(new ArrayList<>());
        }
        
        draftContent.getMaterials().getAudios().add(audio);
    }
    
    /**
     * 添加特效到草稿
     * @param draftContent 草稿内容
     * @param effect 特效元素
     */
    public static void addEffectToDraft(DraftContent draftContent, Effect effect) {
        if (draftContent.getMaterials() == null) {
            draftContent.setMaterials(new Materials());
        }
        
        if (draftContent.getMaterials().getEffects() == null) {
            draftContent.getMaterials().setEffects(new ArrayList<>());
        }
        
        draftContent.getMaterials().getEffects().add(effect);
    }
    
    /**
     * 添加转场到草稿
     * @param draftContent 草稿内容
     * @param transition 转场元素
     */
    public static Transition addTransitionToDraft(DraftContent draftContent, Transition transition) {
        if (draftContent.getMaterials() == null) {
            draftContent.setMaterials(new Materials());
        }
        
        if (draftContent.getMaterials().getTransitions() == null) {
            draftContent.getMaterials().setTransitions(new ArrayList<>());
        }
        Transition addTransition = new Transition();
        BeanUtil.copyProperties(transition, addTransition);
        addTransition.setId(UUID.randomUUID().toString());
        addTransition.setCategory_id("39663");
        addTransition.setCategory_name("热门");
        addTransition.setPlatform("all");
        addTransition.setType("transition");
        draftContent.getMaterials().getTransitions().add(addTransition);
        return addTransition;
    }
    
    /**
     * 添加视频效果到草稿
     * @param draftContent 草稿内容
     * @param videoEffect 视频效果元素
     */
    public static void addVideoEffectToDraft(DraftContent draftContent, VideoEffect videoEffect) {
        if (draftContent.getMaterials() == null) {
            draftContent.setMaterials(new Materials());
        }
        
        if (draftContent.getMaterials().getVideo_effects() == null) {
            draftContent.getMaterials().setVideo_effects(new ArrayList<>());
        }
        
        draftContent.getMaterials().getVideo_effects().add(videoEffect);
    }
    
    /**
     * 为元素添加动画
     * @param materialAnimation 材料动画
     * @param animation 动画元素
     */
    public static void addAnimationToElement(MaterialAnimation materialAnimation, Animation animation) {
        if (materialAnimation.getAnimations() == null) {
            materialAnimation.setAnimations(new ArrayList<>());
        }
        
        materialAnimation.getAnimations().add(animation);
    }
    
    /**
     * 为文字添加入场动画
     * @param text 文字元素
     * @param inAnimation 入场动画
     */
    public static void addTextInAnimation(Text text, Animation inAnimation) {
        if (text.getAnimations() == null) {
            text.setAnimations(new TextAnimation());
        }
        
        text.getAnimations().setInAnimation(inAnimation);
    }
    
    /**
     * 为文字添加出场动画
     * @param text 文字元素
     * @param outAnimation 出场动画
     */
    public static void addTextOutAnimation(Text text, Animation outAnimation) {
        if (text.getAnimations() == null) {
            text.setAnimations(new TextAnimation());
        }
        
        text.getAnimations().setOutAnimation(outAnimation);
    }
    
    /**
     * 添加材料动画到草稿
     * @param draftContent 草稿内容
     * @param materialAnimation 材料动画
     */
    public static void addMaterialAnimationToDraft(DraftContent draftContent, MaterialAnimation materialAnimation) {
        if (draftContent.getMaterials() == null) {
            draftContent.setMaterials(new Materials());
        }
        
        if (draftContent.getMaterials().getMaterial_animations() == null) {
            draftContent.getMaterials().setMaterial_animations(new ArrayList<>());
        }
        
        draftContent.getMaterials().getMaterial_animations().add(materialAnimation);
    }
    
    /**
     * 为草稿添加文字轨道和片段
     * @param draftContent 草稿内容
     * @param text 文字元素
     * @param start 开始时间（微秒）
     * @param duration 文字显示时长（微秒）
     * @param materialAnimationId 材料动画ID
     */
    public static void addTextTrackAndSegment(DraftContent draftContent, Text text, long start, long duration, String materialAnimationId,
                                              double transformX, double tranFormY, double scaleX, double scaleY, String trackName) {
        if (draftContent.getTracks() == null) {
            return;
        }

        if (StringUtils.isBlank(trackName)) {
            trackName = "";
        }

        Track textTrack = null;
        for (Track track : draftContent.getTracks()) {
            if (trackName.equals(track.getName())) {
                textTrack = track;
                break;
            }
        }

        if (textTrack == null) {
            // 创建文字轨道
            textTrack = new Track();
            textTrack.setId(java.util.UUID.randomUUID().toString());
            textTrack.setType("text");
            textTrack.setAttribute(0);
            textTrack.setFlag(0);
            textTrack.setIs_default_name(true);
            textTrack.setName(StringUtils.isNotBlank(trackName) ? trackName : java.util.UUID.randomUUID().toString());
        }
        

        
        // 创建文字片段
        Segment segment = new Segment();
        segment.setId(java.util.UUID.randomUUID().toString());
        segment.setMaterial_id(text.getId());
        segment.setTarget_timerange(new TimeRange());
        segment.getTarget_timerange().setStart(start);
        segment.getTarget_timerange().setDuration(duration);
        segment.setRender_index(15000); // 设置渲染索引，确保在其他元素之上
        segment.setTrack_render_index(3); // 设置轨道渲染索引
        segment.setTrack_attribute(0);
        segment.setVisible(true);
        segment.setCartoon(false);
        segment.setEnable_adjust(false);
        segment.setEnable_color_curves(true);
        segment.setEnable_color_wheels(true);
        segment.setEnable_lut(false);
        segment.setEnable_smart_color_adjust(false);
        segment.setIs_placeholder(false);
        segment.setIs_tone_modify(false);
        segment.setLast_nonzero_volume(1.0);
        segment.setReverse(false);
        segment.setTemplate_scene("default");
        segment.setTemplate_id("");
        segment.setKeyframe_refs(new java.util.ArrayList<>());
        segment.setCommon_keyframes(new java.util.ArrayList<>());

        // 添加clip对象配置，这是视频播放必需的
        Clip clip = new Clip();
        clip.setAlpha(1.0);
        clip.setFlip(new Flip());
        clip.getFlip().setHorizontal(false);
        clip.getFlip().setVertical(false);
        clip.setRotation(0.0);
        clip.setScale(new Scale());
        clip.getScale().setX(scaleX);
        clip.getScale().setY(scaleY);
        clip.setTransform(new Transform());
        clip.getTransform().setX(transformX);
        clip.getTransform().setY(tranFormY);
        segment.setClip(clip);
        
        // 设置额外材料引用（动画等）
        java.util.List<String> extraMaterialRefs = new java.util.ArrayList<>();
        // 添加材料动画ID
        if (materialAnimationId != null && !materialAnimationId.isEmpty()) {
            extraMaterialRefs.add(materialAnimationId);
        }
        // 添加文字动画引用
        if (text.getAnimations() != null) {
            // 如果有入场动画，添加动画引用
            if (text.getAnimations().getInAnimation() != null) {
                extraMaterialRefs.add(text.getAnimations().getInAnimation().getId());
            }
            // 如果有出场动画，添加动画引用
            if (text.getAnimations().getOutAnimation() != null) {
                extraMaterialRefs.add(text.getAnimations().getOutAnimation().getId());
            }
        }
        segment.setExtra_material_refs(extraMaterialRefs);
        
        // 将片段添加到轨道
        java.util.List<Segment> segments = textTrack.getSegments();
        if (segments == null) {
            segments = new java.util.ArrayList<>();
        }
        segments.add(segment);
        textTrack.setSegments(segments);
        
        // 将轨道添加到草稿
        draftContent.getTracks().add(textTrack);
    }
    
    /**
     * 为草稿添加视频轨道和片段
     * @param draftContent 草稿内容
     * @param video 视频元素
     * @param start 开始时间（微秒）
     * @param duration 视频显示时长（微秒）
     */
    public static void addVideoTrackAndSegment(DraftContent draftContent, Video video, long start, long duration) {
        addVideoTrackAndSegment(draftContent, video, start, duration, null);
    }
    
    /**
     * 为草稿添加视频轨道和片段（支持动画ID）
     * @param draftContent 草稿内容
     * @param video 视频元素
     * @param start 开始时间（微秒）
     * @param duration 视频显示时长（微秒）
     * @param animationId 动画ID（可选）
     */
    public static void addVideoTrackAndSegment(DraftContent draftContent, Video video, long start, long duration, String animationId) {
        if (draftContent.getTracks() == null) {
            return;
        }
        
        // 查找现有的视频轨道或创建新的视频轨道
        Track videoTrack = null;
        for (Track track : draftContent.getTracks()) {
            if ("video".equals(track.getType())) {
                videoTrack = track;
                break;
            }
        }
        
        // 如果没有找到视频轨道，则创建一个新的
        if (videoTrack == null) {
            videoTrack = new Track();
            videoTrack.setId(java.util.UUID.randomUUID().toString());
            videoTrack.setType("video");
            videoTrack.setAttribute(0);
            videoTrack.setFlag(0);
            videoTrack.setIs_default_name(true);
            videoTrack.setName("");
            videoTrack.setSegments(new java.util.ArrayList<>());
            draftContent.getTracks().add(videoTrack);
        }
        
        // 创建视频片段
        Segment segment = new Segment();
        segment.setId(java.util.UUID.randomUUID().toString());
        segment.setMaterial_id(video.getId());
        segment.setTarget_timerange(new TimeRange());
        segment.getTarget_timerange().setStart(start);
        segment.getTarget_timerange().setDuration(duration);
        segment.setRender_index(0); // 设置渲染索引
        segment.setTrack_render_index(0); // 设置轨道渲染索引
        segment.setTrack_attribute(0);
        segment.setVisible(true);
        segment.setCartoon(false);
        segment.setEnable_adjust(true);
        segment.setEnable_color_curves(true);
        segment.setEnable_color_wheels(true);
        segment.setEnable_lut(true);
        segment.setEnable_smart_color_adjust(false);
        segment.setIs_placeholder(false);
        segment.setIs_tone_modify(false);
        segment.setLast_nonzero_volume(1.0);
        segment.setReverse(false);
        segment.setTemplate_scene("default");
        segment.setTemplate_id("");
        segment.setKeyframe_refs(new java.util.ArrayList<>());
        segment.setCommon_keyframes(new java.util.ArrayList<>());
        segment.setExtra_material_refs(new java.util.ArrayList<>());
        
        // 如果提供了动画ID，则设置动画引用
        if (animationId != null) {
            java.util.List<String> extraMaterialRefs = new java.util.ArrayList<>();
            extraMaterialRefs.add(animationId);
            segment.setExtra_material_refs(extraMaterialRefs);
        }
        
        // 添加clip对象配置，这是视频播放必需的
        Clip clip = new Clip();
        clip.setAlpha(1.0);
        clip.setFlip(new Flip());
        clip.getFlip().setHorizontal(false);
        clip.getFlip().setVertical(false);
        clip.setRotation(0.0);
        clip.setScale(new Scale());
        clip.getScale().setX(1.0);
        clip.getScale().setY(1.0);
        clip.setTransform(new Transform());
        clip.getTransform().setX(0.0);
        clip.getTransform().setY(0.0);
        segment.setClip(clip);
        
        // 将片段添加到轨道
        videoTrack.getSegments().add(segment);
    }
    
    /**
     * 为草稿添加文字轨道和片段（兼容旧版本）
     * @param draftContent 草稿内容
     * @param text 文字元素
     * @param duration 文字显示时长（微秒）
     */
    public static void addTextTrackAndSegment(DraftContent draftContent, Text text, long start, long duration) {
        addTextTrackAndSegment(draftContent, text, start, duration, null, 0, 0, 1.0, 1.0, "");
    }
    
    /**
     * 创建预定义的文字入场动画（通过动画元数据实例）
     * @param animationMeta 动画元数据实例
     * @return Animation对象
     */
    public static Animation createPredefinedTextIntroAnimation(AnimationMeta animationMeta) {
        Animation animation = new Animation();
        animation.setId(java.util.UUID.randomUUID().toString());
        animation.setName(animationMeta.getTitle());
        animation.setType("in");
        animation.setCategory_name("入场");
        animation.setDuration(animationMeta.getDurationInMicroseconds()); // 使用正确的微秒时长
        animation.setMaterial_type("text");
        // 设置动画资源路径等信息
        animation.setPath("C:/Users/Administrator/AppData/Local/JianyingPro/User Data/Cache/effect/" + animationMeta.getEffectId() + "/" + animationMeta.getMd5());
        animation.setResource_id(animationMeta.getResourceId());
        animation.setPlatform("all");
        return animation;
    }
    
    /**
     * 创建预定义的文字出场动画（通过动画元数据实例）
     * @param animationMeta 动画元数据实例
     * @return Animation对象
     */
    public static Animation createPredefinedTextOutroAnimation(AnimationMeta animationMeta) {
        Animation animation = new Animation();
        animation.setId(java.util.UUID.randomUUID().toString());
        animation.setName(animationMeta.getTitle());
        animation.setType("out");
        animation.setCategory_name("出场");
        animation.setDuration(animationMeta.getDurationInMicroseconds()); // 使用正确的微秒时长
        animation.setMaterial_type("text");
        // 设置动画资源路径等信息
        animation.setPath("C:/Users/Administrator/AppData/Local/JianyingPro/User Data/Cache/effect/" + animationMeta.getEffectId() + "/" + animationMeta.getMd5());
        animation.setResource_id(animationMeta.getResourceId());
        animation.setPlatform("all");
        return animation;
    }
    
    /**
     * 添加预定义的文字入场动画到文字元素
     * @param text 文字元素
     * @param animationMeta 入场动画元数据
     */
    public static void addPredefinedTextIntroAnimation(Text text, AnimationMeta animationMeta) {
        Animation inAnimation = createPredefinedTextIntroAnimation(animationMeta);
        addTextInAnimation(text, inAnimation);
    }
    
    /**
     * 添加预定义的文字出场动画到文字元素
     * @param text 文字元素
     * @param animationMeta 出场动画元数据
     */
    public static void addPredefinedTextOutroAnimation(Text text, AnimationMeta animationMeta) {
        Animation outAnimation = createPredefinedTextOutroAnimation(animationMeta);
        addTextOutAnimation(text, outAnimation);
    }
    
    /**
     * 为文字添加预定义的入场和出场动画
     * @param text 文字元素
     * @param introAnimation 入场动画元数据
     * @param outroAnimation 出场动画元数据
     */
    public static void addPredefinedTextAnimations(Text text, AnimationMeta introAnimation, AnimationMeta outroAnimation) {
        // 添加入场动画
        if (introAnimation != null) {
            addPredefinedTextIntroAnimation(text, introAnimation);
        }
        // 添加出场动画
        if (outroAnimation != null) {
            addPredefinedTextOutroAnimation(text, outroAnimation);
        }
    }
    
    /**
     * 创建视频元素（增强版）
     * @param path 视频路径
     * @param duration 视频时长（微秒）
     * @param width 视频宽度
     * @param height 视频高度
     * @return Video对象
     */
    public static Video createEnhancedVideo(String path, long duration, int width, int height) {
        Video video = new Video();
        video.setId(java.util.UUID.randomUUID().toString());
        video.setPath(path);
        video.setDuration(duration);
        video.setWidth(width);
        video.setHeight(height);
        video.setType("video");
        video.setSource(0);
        video.setSource_platform(0);
        video.setCheck_flag(63487);
        video.setCategory_name("local");
        video.setLocal_material_id(UUID.randomUUID().toString());
        video.setCrop_ratio("free");
        video.setCrop_scale(1.0);
        video.setHas_audio(false);
        // 使用Lombok生成的正确setter方法名
        video.set_ai_generate_content(false);
        video.set_copyright(false);
        video.set_text_edit_overdub(false);
        video.set_unified_beauty_mode(false);
        video.setTeam_id("");
        video.setPicture_from("none");
        video.setPicture_set_category_id("");
        video.setPicture_set_category_name("");
        video.setExtra_type_option(0);
        video.setAigc_type("none");
        video.setIntensifies_path("");
        video.setIntensifies_audio_path("");
        video.setReverse_path("");
        video.setReverse_intensifies_path("");
        video.setCartoon_path("");
        video.setMedia_path("");
        video.setOrigin_material_id("");
        video.setMaterial_id("");
        video.setMaterial_name(new File(path).getName());
        video.setMaterial_url("");
        video.setRequest_id("");
        video.setFormula_id("");
        video.setLocal_id("");
        
        // 设置crop对象
        VideoCropInfo crop = new VideoCropInfo();
        crop.setLowerLeftX(0.0);
        crop.setLowerLeftY(1.0);
        crop.setLowerRightX(1.0);
        crop.setLowerRightY(1.0);
        crop.setUpperLeftX(0.0);
        crop.setUpperLeftY(0.0);
        crop.setUpperRightX(1.0);
        crop.setUpperRightY(0.0);
        video.setCrop(crop);
        
        // 设置matting对象
        Matting matting = new Matting();
        matting.setFlag(0);
        matting.setHas_use_quick_brush(false);
        matting.setHas_use_quick_eraser(false);
        matting.setInteractiveTime(new java.util.ArrayList<>());
        matting.setPath("");
        matting.setStrokes(new java.util.ArrayList<>());
        video.setMatting(matting);
        
        // 设置stable对象
        Stable stable = new Stable();
        stable.setMatrix_path("");
        stable.setStable_level(0);
        TimeRange timeRange = new TimeRange();
        timeRange.setDuration(0);
        timeRange.setStart(0);
        stable.setTime_range(timeRange);
        video.setStable(stable);
        
        // 设置video_algorithm对象（更完整的配置）
        VideoAlgorithm videoAlgorithm = new VideoAlgorithm();
        videoAlgorithm.setPath("");
        videoAlgorithm.setAlgorithms(new java.util.ArrayList<>());
        videoAlgorithm.setGameplay_configs(new java.util.ArrayList<>());
        videoAlgorithm.setComplement_frame_config(null);
        videoAlgorithm.setDeflicker(null);
        videoAlgorithm.setMotion_blur_config(null);
        videoAlgorithm.setNoise_reduction(null);
        videoAlgorithm.setQuality_enhance(null);
        videoAlgorithm.setTime_range(null);
        video.setVideo_algorithm(videoAlgorithm);
        
        // 设置其他必要属性
        video.setObject_locked(null);
        video.setFreeze(null);
        video.setAudio_fade(null);
        video.setSmart_motion(null);
        
        return video;
    }
    
    /**
     * 创建预定义的视频出场动画（通过动画元数据实例）
     * @param animationMeta 动画元数据实例
     * @return Animation对象
     */
    public static Animation createPredefinedVideoOutroAnimation(AnimationMeta animationMeta) {
        Animation animation = new Animation();
        animation.setId(java.util.UUID.randomUUID().toString());
        animation.setName(animationMeta.getTitle());
        animation.setType("out");
        animation.setCategory_name("出场");
        animation.setDuration(animationMeta.getDurationInMicroseconds()); // 使用正确的微秒时长
        animation.setMaterial_type("video");
        // 设置动画资源路径等信息
        animation.setPath("C:/Users/Administrator/AppData/Local/JianyingPro/User Data/Cache/effect/" + animationMeta.getEffectId() + "/" + animationMeta.getMd5());
        animation.setResource_id(animationMeta.getResourceId());
        animation.setPlatform("all");
        return animation;
    }
    
    /**
     * 添加预定义的视频出场动画到视频元素
     * @param video 视频元素
     * @param animationMeta 出场动画元数据
     */
    public static void addPredefinedVideoOutroAnimation(Video video, AnimationMeta animationMeta) {
        Animation outAnimation = createPredefinedVideoOutroAnimation(animationMeta);
        // 为视频添加出场动画的逻辑
        // 这里需要根据视频动画的具体实现来添加
    }

    /**
     * 创建预定义的视频出场动画（通过动画元数据实例）
     * @param animationMeta 动画元数据实例
     * @return Animation对象
     */
    public static Animation createPredefinedVideoInroAnimation(AnimationMeta animationMeta) {
        Animation animation = new Animation();
        animation.setId(java.util.UUID.randomUUID().toString());
        animation.setName(animationMeta.getTitle());
        animation.setType("in");
        animation.setCategory_name("入场");
        animation.setDuration(animationMeta.getDurationInMicroseconds()); // 使用正确的微秒时长
        animation.setMaterial_type("video");
        // 设置动画资源路径等信息
        animation.setPath("C:/Users/Administrator/AppData/Local/JianyingPro/User Data/Cache/effect/" + animationMeta.getEffectId() + "/" + animationMeta.getMd5());
        animation.setResource_id(animationMeta.getResourceId());
        animation.setPlatform("all");
        return animation;
    }

    /**
     * 添加预定义的视频入场动画到视频元素
     * @param video 视频元素
     * @param animationMeta 入场动画元数据
     */
    public static void addPredefinedVideoInroAnimation(Video video, AnimationMeta animationMeta) {
        Animation outAnimation = createPredefinedVideoInroAnimation(animationMeta);
        // 为视频添加入场动画的逻辑
        // 这里需要根据视频动画的具体实现来添加
    }
    
    /**
     * 为草稿添加特效轨道和片段
     * @param draftContent 草稿内容
     * @param videoEffect 视频特效元素
     * @param start 开始时间（微秒）
     * @param duration 特效显示时长（微秒）
     */
    public static void addEffectTrackAndSegment(DraftContent draftContent, VideoEffect videoEffect, long start, long duration) {
        if (draftContent.getTracks() == null) {
            return;
        }
        
        // 创建特效轨道
        Track effectTrack = new Track();
        effectTrack.setId(java.util.UUID.randomUUID().toString());
        effectTrack.setType("effect");
        effectTrack.setAttribute(0);
        effectTrack.setFlag(0);
        effectTrack.setIs_default_name(true);
        effectTrack.setName("");
        
        // 创建特效片段
        Segment segment = new Segment();
        segment.setId(java.util.UUID.randomUUID().toString());
        segment.setMaterial_id(videoEffect.getId());
        segment.setTarget_timerange(new TimeRange());
        segment.getTarget_timerange().setStart(start);
        segment.getTarget_timerange().setDuration(duration);
        segment.setRender_index(11002); // 设置渲染索引，确保在正确的位置显示
        segment.setTrack_render_index(5); // 设置轨道渲染索引
        segment.setTrack_attribute(0);
        segment.setVisible(true);
        segment.setCartoon(false);
        segment.setEnable_adjust(false);
        segment.setEnable_color_curves(true);
        segment.setEnable_color_wheels(true);
        segment.setEnable_lut(false);
        segment.setEnable_smart_color_adjust(false);
        segment.setIs_placeholder(false);
        segment.setIs_tone_modify(false);
        segment.setLast_nonzero_volume(1.0);
        segment.setReverse(false);
        segment.setTemplate_scene("default");
        segment.setTemplate_id("");
        segment.setKeyframe_refs(new java.util.ArrayList<>());
        segment.setCommon_keyframes(new java.util.ArrayList<>());
        segment.setExtra_material_refs(new java.util.ArrayList<>());
        
        // 将片段添加到轨道
        java.util.List<Segment> segments = new java.util.ArrayList<>();
        segments.add(segment);
        effectTrack.setSegments(segments);
        
        // 将轨道添加到草稿
        draftContent.getTracks().add(effectTrack);
    }
    
    /**
     * 为草稿添加音频轨道和片段
     * @param draftContent 草稿内容
     * @param audio 音频元素
     * @param start 开始时间（微秒）
     * @param duration 音频显示时长（微秒）
     */
    public static void addAudioTrackAndSegment(DraftContent draftContent, Audio audio, long start, long duration, Double volume, String trackName) {
        if (draftContent.getTracks() == null) {
            return;
        }
        
        // 查找现有的音频轨道或创建新的音频轨道
        Track audioTrack = null;
        for (Track track : draftContent.getTracks()) {
            if (trackName.equals(track.getName())) {
                audioTrack = track;
                break;
            }
        }
        
        // 如果没有找到音频轨道，则创建一个新的
        if (audioTrack == null) {
            audioTrack = new Track();
            audioTrack.setId(java.util.UUID.randomUUID().toString());
            audioTrack.setType("audio");
            audioTrack.setAttribute(0);
            audioTrack.setFlag(0);
            audioTrack.setIs_default_name(true);
            audioTrack.setName("");
            audioTrack.setSegments(new java.util.ArrayList<>());
            draftContent.getTracks().add(audioTrack);
        }
        
        // 创建音频片段
        Segment segment = new Segment();
        segment.setId(java.util.UUID.randomUUID().toString());
        segment.setMaterial_id(audio.getId());
        segment.setTarget_timerange(new TimeRange());
        segment.getTarget_timerange().setStart(start);
        segment.getTarget_timerange().setDuration(duration);
        segment.setRender_index(0); // 设置渲染索引
        segment.setTrack_render_index(0); // 设置轨道渲染索引
        segment.setTrack_attribute(0);
        segment.setVisible(true);
        segment.setCartoon(false);
        segment.setEnable_adjust(false);
        segment.setEnable_color_curves(true);
        segment.setEnable_color_wheels(true);
        segment.setEnable_lut(false);
        segment.setEnable_smart_color_adjust(false);
        segment.setIs_placeholder(false);
        segment.setIs_tone_modify(false);
        segment.setLast_nonzero_volume(1.0);
        segment.setReverse(false);
        segment.setTemplate_scene("default");
        segment.setTemplate_id("");
        segment.setVolume(volume);
        segment.setKeyframe_refs(new java.util.ArrayList<>());
        segment.setCommon_keyframes(new java.util.ArrayList<>());
        segment.setExtra_material_refs(new java.util.ArrayList<>());
        
        // 将片段添加到轨道
        audioTrack.getSegments().add(segment);
    }
    
    /**
     * 为片段创建位置关键帧（X轴）
     * @param timeOffset 时间偏移（微秒）
     * @param positionX X坐标值
     * @return 关键帧对象
     */
    public static Keyframe createPositionXKeyframe(long[] timeOffset, int[] positionX) {

        Keyframe keyframe = new Keyframe();
        keyframe.setId(UUID.randomUUID().toString());
        keyframe.setProperty_type("KFTypePositionX");
        keyframe.setMaterial_id("");
        if (timeOffset == null || timeOffset.length == 0 || positionX == null || positionX.length == 0) {
            return keyframe;
        }
        
        List<KeyframeData> keyframeList = new ArrayList<>();
        for (int i = 0; i < positionX.length; i++) {
            KeyframeData data = new KeyframeData();
            data.setCurveType("Line");
            data.setGraphID("");
            data.setId(UUID.randomUUID().toString());
            data.setLeft_control(new ControlPoint());
            data.setRight_control(new ControlPoint());
            data.setTime_offset(timeOffset[i]);
            data.setValues(Arrays.asList((double)positionX[i]/ Config.SCREEN_WIDTH));
            keyframeList.add(data);
        };
        keyframe.setKeyframe_list(keyframeList);
        
        return keyframe;
    }

    /**
     * 为片段创建位置关键帧（Y轴）
     * @param timeOffset 时间偏移（微秒）
     * @param positionY Y坐标值
     * @return 关键帧对象
     */
    public static Keyframe createPositionYKeyframe(long timeOffset[], int[] positionY) {

        Keyframe keyframe = new Keyframe();
        keyframe.setId(UUID.randomUUID().toString());
        keyframe.setProperty_type("KFTypePositionY");
        keyframe.setMaterial_id("");
        if (timeOffset == null || timeOffset.length == 0 || positionY == null || positionY.length == 0) {
            return keyframe;
        }
        List<KeyframeData> keyframeList = new ArrayList<>();
        for (int i = 0; i < positionY.length; i++) {
            KeyframeData data = new KeyframeData();
            data.setCurveType("Line");
            data.setGraphID("");
            data.setId(UUID.randomUUID().toString());
            data.setLeft_control(new ControlPoint());
            data.setRight_control(new ControlPoint());
            data.setTime_offset(timeOffset[i]);
            data.setValues(Arrays.asList((double)positionY[i]/ Config.SCREEN_HEIGHT));
            keyframeList.add(data);
        };
        keyframe.setKeyframe_list(keyframeList);
        
        return keyframe;
    }

    /**
     * 为片段创建缩放关键帧（X轴）
     * @param timeOffset 时间偏移（微秒）
     * @param scaleX 缩放X值
     * @return 关键帧对象
     */
    public static Keyframe createScaleXKeyframe(long[] timeOffset, double[] scaleX) {

        Keyframe keyframe = new Keyframe();
        keyframe.setId(UUID.randomUUID().toString());
        keyframe.setProperty_type("KFTypeScaleX");
        keyframe.setMaterial_id("");
        if (timeOffset == null || timeOffset.length == 0 || scaleX == null || scaleX.length == 0) {
            return keyframe;
        }
        List<KeyframeData> keyframeList = new ArrayList<>();
        for (int i = 0; i < scaleX.length; i++) {
            KeyframeData data = new KeyframeData();
            data.setCurveType("Line");
            data.setGraphID("");
            data.setId(UUID.randomUUID().toString());
            data.setLeft_control(new ControlPoint());
            data.setRight_control(new ControlPoint());
            data.setTime_offset(timeOffset[i]);
            data.setValues(Arrays.asList(scaleX[i]));
            keyframeList.add(data);
        };
        keyframe.setKeyframe_list(keyframeList);
        
        return keyframe;
    }

    /**
     * 为片段创建缩放关键帧（Y轴）
     * @param timeOffset 时间偏移（微秒）
     * @param scaleY 缩放Y值
     * @return 关键帧对象
     */
    public static Keyframe createScaleYKeyframe(long[] timeOffset, double[] scaleY) {

        Keyframe keyframe = new Keyframe();
        keyframe.setId(UUID.randomUUID().toString());
        keyframe.setProperty_type("KFTypeScaleY");
        keyframe.setMaterial_id("");
        if (timeOffset == null || timeOffset.length == 0 || scaleY == null || scaleY.length == 0) {
            return keyframe;
        }
        List<KeyframeData> keyframeList = new ArrayList<>();
        for (int i = 0; i < scaleY.length; i++) {
            KeyframeData data = new KeyframeData();
            data.setCurveType("Line");
            data.setGraphID("");
            data.setId(UUID.randomUUID().toString());
            data.setLeft_control(new ControlPoint());
            data.setRight_control(new ControlPoint());
            data.setTime_offset(timeOffset[i]);
            data.setValues(Arrays.asList(scaleY[i]));
            keyframeList.add(data);
        };
        keyframe.setKeyframe_list(keyframeList);
        
        return keyframe;
    }

    /**
     * 为片段创建旋转关键帧
     * @param timeOffset 时间偏移（微秒）
     * @param rotation 旋转角度值
     * @return 关键帧对象
     */
    public static Keyframe createRotationKeyframe(long[] timeOffset, double[] rotation) {

        Keyframe keyframe = new Keyframe();
        keyframe.setId(UUID.randomUUID().toString());
        keyframe.setProperty_type("KFTypeRotation");
        keyframe.setMaterial_id("");
        if (timeOffset == null || timeOffset.length == 0 || rotation == null || rotation.length == 0) {
            return keyframe;
        }
        List<KeyframeData> keyframeList = new ArrayList<>();
        for (int i = 0; i < rotation.length; i++) {
            KeyframeData data = new KeyframeData();
            data.setCurveType("Line");
            data.setGraphID("");
            data.setId(UUID.randomUUID().toString());
            data.setLeft_control(new ControlPoint());
            data.setRight_control(new ControlPoint());
            data.setTime_offset(timeOffset[i]);
            data.setValues(Arrays.asList(rotation[i]));
            keyframeList.add(data);
        };
        keyframe.setKeyframe_list(keyframeList);
        
        return keyframe;
    }

    /**
     * 为片段创建透明度关键帧
     * @param timeOffset 时间偏移（微秒）
     * @param alpha 透明度值
     * @return 关键帧对象
     */
    public static Keyframe createAlphaKeyframe(long[] timeOffset, double[] alpha) {

        Keyframe keyframe = new Keyframe();
        keyframe.setId(UUID.randomUUID().toString());
        keyframe.setProperty_type("KFTypeAlpha");
        keyframe.setMaterial_id("");
        if (timeOffset == null || timeOffset.length == 0 || alpha == null || alpha.length == 0) {
            return keyframe;
        }
        List<KeyframeData> keyframeList = new ArrayList<>();
        for (int i = 0; i < alpha.length; i++) {
            KeyframeData data = new KeyframeData();
            data.setCurveType("Line");
            data.setGraphID("");
            data.setId(UUID.randomUUID().toString());
            data.setLeft_control(new ControlPoint());
            data.setRight_control(new ControlPoint());
            data.setTime_offset(timeOffset[i]);
            data.setValues(Arrays.asList(alpha[i]));
            keyframeList.add(data);
        };
        keyframe.setKeyframe_list(keyframeList);
        
        return keyframe;
    }

    /**
     * 为片段添加关键帧
     * @param segment 片段
     * @param keyframe 关键帧
     */
    public static void addKeyframeToSegment(Segment segment, Keyframe keyframe) {

        if (segment.getCommon_keyframes() == null) {
            segment.setCommon_keyframes(new ArrayList<>());
        }
        
        // 检查是否已存在相同类型的Keyframe，如果存在则替换，否则添加
        replaceOrAddKeyframe(segment.getCommon_keyframes(), keyframe);
    }
    
    /**
     * 为视频效果添加关键帧
     * @param videoEffect 视频效果
     * @param keyframe 关键帧
     */
    public static void addKeyframeToVideoEffect(VideoEffect videoEffect, Keyframe keyframe) {
        if (videoEffect.getCommon_keyframes() == null) {
            videoEffect.setCommon_keyframes(new ArrayList<>());
        }
        
        // 检查是否已存在相同类型的Keyframe，如果存在则替换，否则添加
        replaceOrAddKeyframe(videoEffect.getCommon_keyframes(), keyframe);
    }
    
    /**
     * 替换或添加关键帧
     * @param keyframes 关键帧列表
     * @param newKeyframe 新关键帧
     */
    private static void replaceOrAddKeyframe(List<Keyframe> keyframes, Keyframe newKeyframe) {
        // 查找是否已存在相同类型的Keyframe
        for (int i = 0; i < keyframes.size(); i++) {
            Keyframe existingKeyframe = keyframes.get(i);
            if (existingKeyframe.getProperty_type().equals(newKeyframe.getProperty_type())) {
                // 如果存在相同类型的Keyframe，则替换它
                keyframes.set(i, newKeyframe);
                return;
            }
        }
        // 如果不存在相同类型的Keyframe，则添加新的
        keyframes.add(newKeyframe);
    }

    /**
     * 为片段添加多个关键帧（位置、缩放、旋转等）
     * @param segment 片段
     * @param keyframes 关键帧列表
     */
    public static void addKeyframesToSegment(Segment segment, List<Keyframe> keyframes) {
        if (segment.getCommon_keyframes() == null) {
            segment.setCommon_keyframes(new ArrayList<>());
        }
        
        for (Keyframe keyframe : keyframes) {
            replaceOrAddKeyframe(segment.getCommon_keyframes(), keyframe);
        }
    }
    
    /**
     * 为视频效果添加多个关键帧
     * @param videoEffect 视频效果
     * @param keyframes 关键帧列表
     */
    public static void addKeyframesToVideoEffect(VideoEffect videoEffect, List<Keyframe> keyframes) {
        if (videoEffect.getCommon_keyframes() == null) {
            videoEffect.setCommon_keyframes(new ArrayList<>());
        }
        
        for (Keyframe keyframe : keyframes) {
            replaceOrAddKeyframe(videoEffect.getCommon_keyframes(), keyframe);
        }
    }

    /**
     * 创建一个完整的关键帧动画示例
     * @param startTime 开始时间（微秒）
     * @param endTime 结束时间（微秒）
     * @param startX 起始X位置
     * @param endX 结束X位置
     * @param startY 起始Y位置
     * @param endY 结束Y位置
     * @return 关键帧列表
     */
    public static List<Keyframe> createPositionAnimation(long startTime, long endTime, double startX, double endX, double startY, double endY) {
        List<Keyframe> keyframes = new ArrayList<>();
        
        // 创建X轴位置关键帧
        Keyframe posXKeyframe = new Keyframe();
        posXKeyframe.setId(UUID.randomUUID().toString());
        posXKeyframe.setProperty_type("KFTypePositionX");
        posXKeyframe.setMaterial_id("");
        
        List<KeyframeData> posXKeyframeList = new ArrayList<>();
        
        // 起始关键帧
        KeyframeData startPosXData = new KeyframeData();
        startPosXData.setCurveType("Line");
        startPosXData.setGraphID("");
        startPosXData.setId(UUID.randomUUID().toString());
        startPosXData.setLeft_control(new ControlPoint());
        startPosXData.setRight_control(new ControlPoint());
        startPosXData.setTime_offset(startTime);
        startPosXData.setValues(Arrays.asList(startX));
        posXKeyframeList.add(startPosXData);
        
        // 结束关键帧
        KeyframeData endPosXData = new KeyframeData();
        endPosXData.setCurveType("Line");
        endPosXData.setGraphID("");
        endPosXData.setId(UUID.randomUUID().toString());
        endPosXData.setLeft_control(new ControlPoint());
        endPosXData.setRight_control(new ControlPoint());
        endPosXData.setTime_offset(endTime);
        endPosXData.setValues(Arrays.asList(endX));
        posXKeyframeList.add(endPosXData);
        
        posXKeyframe.setKeyframe_list(posXKeyframeList);
        keyframes.add(posXKeyframe);
        
        // 创建Y轴位置关键帧
        Keyframe posYKeyframe = new Keyframe();
        posYKeyframe.setId(UUID.randomUUID().toString());
        posYKeyframe.setProperty_type("KFTypePositionY");
        posYKeyframe.setMaterial_id("");
        
        List<KeyframeData> posYKeyframeList = new ArrayList<>();
        
        // 起始关键帧
        KeyframeData startPosYData = new KeyframeData();
        startPosYData.setCurveType("Line");
        startPosYData.setGraphID("");
        startPosYData.setId(UUID.randomUUID().toString());
        startPosYData.setLeft_control(new ControlPoint());
        startPosYData.setRight_control(new ControlPoint());
        startPosYData.setTime_offset(startTime);
        startPosYData.setValues(Arrays.asList(startY));
        posYKeyframeList.add(startPosYData);
        
        // 结束关键帧
        KeyframeData endPosYData = new KeyframeData();
        endPosYData.setCurveType("Line");
        endPosYData.setGraphID("");
        endPosYData.setId(UUID.randomUUID().toString());
        endPosYData.setLeft_control(new ControlPoint());
        endPosYData.setRight_control(new ControlPoint());
        endPosYData.setTime_offset(endTime);
        endPosYData.setValues(Arrays.asList(endY));
        posYKeyframeList.add(endPosYData);
        
        posYKeyframe.setKeyframe_list(posYKeyframeList);
        keyframes.add(posYKeyframe);
        
        return keyframes;
    }
}